﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;

namespace Leo.Core.AbpFreeSql
{
    [DependsOn(typeof(AbpDddDomainModule))]
    public class AbpFreeSqlDbModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        { 
            var configuration = context.Services.GetConfiguration();
            var connectionString = configuration.GetConnectionString("Default");
            IFreeSql freeSql = new FreeSql.FreeSqlBuilder()
                .UseConnectionString(FreeSql.DataType.SqlServer, connectionString)
                //.UseAutoSyncStructure(true) 
                .Build(); 
            context.Services.AddSingleton<IFreeSql>(freeSql);
        }
    }
}